//
//  UIButton+ImageAndTitleAlignmentCenter.m
//  WProjectForNative
//
//  Created by HuangZhen on 16/9/10.
//  Copyright © 2016年 HuangZhen. All rights reserved.
//

#import "UIButton+ImageAndTitleAlignmentCenter.h"

@implementation UIButton (ImageAndTitleAlignmentCenter)

- (void)centerImageAndTitle:(float)spacing {
    CGSize imageSize = self.imageView.frame.size;
    CGSize titleSize = self.titleLabel.frame.size;
    
    CGFloat totalHeight = (imageSize.height + titleSize.height + spacing);
    
    self.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight - imageSize.height)-4, 0.0, 0.0, - titleSize.width);
    self.titleEdgeInsets = UIEdgeInsetsMake(0.0, - imageSize.width, - (totalHeight - titleSize.height), 0.0);
    
}


- (void)centerImageAndTitle {
    const int DEFAULT_SPACING = 6.0f;
    [self centerImageAndTitle:DEFAULT_SPACING];
}
@end
